﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace OmronProject
{
    public partial class Form1 : Form
    {
        KeyboardHook hook = new KeyboardHook();
        public Form1()
        {
            InitializeComponent();
            hook.KeyPressed += new EventHandler <KeyPressedEventArgs> (hook_KeyPressed);

            // register the control + alt + F12 combination as hot key.
            //ModifierKeys K = new ModifierKeys();
            hook.RegisterHotKey(new ModifierKeys(), Keys.F1);
            hook.RegisterHotKey(new ModifierKeys(),Keys.F2);
            hook.RegisterHotKey(new ModifierKeys(), Keys.F3);
            hook.RegisterHotKey(new ModifierKeys(), Keys.F4);
            hook.RegisterHotKey(new ModifierKeys(), Keys.F5);
        }

        void hook_KeyPressed(object sender, KeyPressedEventArgs e)
    {
        switch (e.Key)
        {
            case Keys.F1:
                setActiveDno();
                break;
            case Keys.F2:
                setActiveBok();
                break;
            case Keys.F3:
                break;
            case Keys.F4:
                break;
            case Keys.F5:
                break;
                
        }
    }

        

        private void omronEdit3_TextChanged(object sender, EventArgs e)
        {

        }
        private void setActiveColorPanel(Panel panel)
        {
            panel.BackColor = Color.Gray;
            foreach (Control i in panel.Controls)
            {
                if (i.GetType() == typeof(Label))
                    i.ForeColor = Color.Lime;
                if (i.GetType() == typeof(OmronEdit.OmronEdit))
                {
                    i.BackColor = Color.Khaki;
                    i.Enabled = true;
                }
            }
        }

        private void setPassiveColorPanel(Panel panel)
        {
            panel.BackColor = SystemColors.Control;
            foreach (Control i in panel.Controls)
            {
                if (i.GetType() == typeof(Label))
                    i.ForeColor = Color.Black;
                if (i.GetType() == typeof(OmronEdit.OmronEdit))
                {
                    i.BackColor = Color.White;
                    i.Enabled = false;
                }
            }
        }
        private void setActiveDno()
        {
            setActiveColorPanel(panel1);
            setPassiveColorPanel(panel2);
            setPassiveColorPanel(panel3);
            setPassiveColorPanel(panel4);
            TTaskDno.Focus();
        }
        private void setActiveBok()
        {
            setActiveColorPanel(panel2);
            setPassiveColorPanel(panel1);
            setPassiveColorPanel(panel3);
            setPassiveColorPanel(panel4);
            omronEdit13.Focus();

        }


        private void button1_Click(object sender, EventArgs e)
        {
            setActiveDno();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            setActiveBok();
        }

        private void Form1_Shown(object sender, EventArgs e)
        {
            TTaskDno.Focus();
            
        }



        
    }
}
